﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Helper.Business.Repository;
using Helper.Business.Implementation;
using Helper.Core.Entity;

namespace Helper.Controllers
{
    public partial class StatusController : BaseController
    {
        IStatusRepository _StatusRepository;

        public StatusController()
        {
            this.LoginNeeded = true;

            if (_StatusRepository == null)
                _StatusRepository = new StatusRepository();
        }


        //
        // GET: /Status/

        public ActionResult Index()
        {
            return View(_StatusRepository.GetAll());
        }

        //
        // GET: /Status/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Status/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Status/Create

        [HttpPost]
        public ActionResult Create(Status collection)
        {
            try
            {
                // TODO: Add insert logic here
                _StatusRepository.Add(collection);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Status/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View(_StatusRepository.FindById(id));
        }

        //
        // POST: /Status/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, Status collection)
        {
            try
            {
                // TODO: Add update logic here
                Status oldStatus = _StatusRepository.FindById(id);
                oldStatus.Conclusive = collection.Conclusive;
                oldStatus.Dependency = collection.Dependency;
                oldStatus.Name = collection.Name;
                oldStatus.PendingSectors = collection.PendingSectors;
                _StatusRepository.Update(oldStatus);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Status/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(_StatusRepository.FindById(id));
        }

        //
        // POST: /Status/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, Status collection)
        {
            try
            {
                // TODO: Add delete logic here
                _StatusRepository.Delete(_StatusRepository.FindById(id));
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
